home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / old-stream / streambuf.cc < prev    next >
C/C++ Source or Header  |  1992-01-17  |  3KB  |  134 lines

  1. /* 
  2. Copyright (C) 1990 Free Software Foundation
  3.     written by Doug Lea (dl@rocky.oswego.edu)
  4.  
  5. This file is part of the GNU C++ Library.  This library is free
  6. software; you can redistribute it and/or modify it under the terms of
  7. the GNU Library General Public License as published by the Free
  8. Software Foundation; either version 2 of the License, or (at your
  9. option) any later version.  This library is distributed in the hope
  10. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  11. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12. PURPOSE.  See the GNU Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with this library; if not, write to the Free Software
  15. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  16. */
  17.  
  18. #ifdef __GNUG__
  19. #pragma implementation
  20. #endif
  21.  
  22. #include <streambuf.h>
  23.  
  24.  
  25. streambuf::streambuf()
  26.      :base(0), gptr(0), pptr(0), eptr(0), alloc(0)
  27. {}
  28.  
  29. streambuf::streambuf(char* buf, int buflen)
  30.      : base(buf), gptr(buf), pptr(buf), eptr(buf+buflen-1), alloc(0)
  31. {}
  32.  
  33. streambuf::~streambuf()
  34. {
  35.   if (alloc && (base != 0)) delete base;
  36. }
  37.  
  38. int streambuf::doallocate()
  39. {
  40.   if (alloc && base != 0) delete base;
  41.   base = new char[BUFSIZ];
  42.   gptr = pptr = base;
  43.   eptr = base + BUFSIZ - 1;
  44.   alloc = 1;
  45.   return BUFSIZ;
  46. }
  47.  
  48. streambuf* streambuf::setbuf(char* buf, int buflen, int preloaded_count)
  49. {
  50.   if (alloc && (base != 0)) delete base;
  51.   alloc = 0;
  52.   base = gptr = buf;
  53.   pptr = base + preloaded_count;
  54.   eptr = base + buflen - 1;
  55.   return this;
  56. }
  57.  
  58. const char* streambuf::name()
  59. {
  60.   return 0;
  61. }
  62.  
  63. int streambuf::overflow(int c)
  64. {
  65.   if (base == 0) allocate();
  66.   return (c == EOF)? c : ((pptr <= eptr)? (*pptr++ = (char)(c)) : EOF);
  67. }
  68.  
  69. int streambuf::underflow()
  70. {
  71.   return EOF;
  72. }
  73.  
  74. int streambuf::sputs(const char* s)
  75. {
  76.   if (s != 0)
  77.   {
  78.     for(; *s != 0; ++s)
  79.     {
  80.       if (must_overflow(*s)) { if (overflow(*s) == EOF) return EOF; }
  81.       else *pptr++ = *s;
  82.     }
  83.   }
  84.   return 0;
  85. }
  86.  
  87. int streambuf::sputsn(const char* s, int len)
  88. {
  89.   for(; --len >= 0; ++s)
  90.   {
  91.     if (must_overflow(*s)) { if (overflow(*s) == EOF) return EOF; }
  92.       else *pptr++ = *s;
  93.   }
  94.   return 0;
  95. }
  96.  
  97.  
  98. int streambuf::is_open()
  99. {
  100.   return 1;
  101. }
  102.  
  103. int streambuf::close()
  104. {
  105.   return 1;
  106. }
  107.  
  108. void streambuf::error()
  109. {
  110.   abort();
  111. }
  112.  
  113. streambuf* streambuf::open(const char*, open_mode)
  114. {
  115.   return 0;
  116. }
  117.  
  118. streambuf* streambuf::open(const char*, io_mode, access_mode)
  119. {
  120.   return 0;
  121. }
  122. streambuf* streambuf::open(const char*, const char*)
  123. {
  124.   return 0;
  125. }
  126. streambuf* streambuf::open(int, io_mode)
  127. {
  128.   return 0;
  129. }
  130. streambuf* streambuf::open(FILE*)
  131. {
  132.   return 0;
  133. }
  134.